Concerning the problems of poor classification performance and high computational overhead of Capsule Network (CapsNet) on complex images with background noise information, an improved capsule network model based on attention mechanism and weight sharing was proposed, called Shared Transformation Matrix CapsNet (STM-CapsNet). The proposed model mainly includes the following improvement. 1) An attention module was introduced into the feature extraction layer of CapsNet, which enabled low-level capsules to focus on entity features related to the classification task. 2) Low-level capsules with close spatial positions were divided into several groups, and each group of low-level capsules was mapped to high-level capsules by sharing transformation matrices, which reduced computational overhead and improved model robustness. 3) The L2 regularization term was added to margin loss and reconstruction loss to prevent model overfitting. Experimental results on three complex image datasets including CIFAR10, SVHN (Street View House Number) and FashionMNIST show that, the above improvements are effective in enhacing the model performance; when the number of iterations is 3, and the number of shared transformation matrices is 5, the average accuracies of STM-CapsNet are 85.26%, 93.17% and 94.96% respectively, the average parameter amount is 8.29 MB, verifying that STM-CapsNet has better performance compared with the baseline models.